<?php

namespace App\Repositories;


use App\Models\GoodsStockHistory;
use App\Interfaces\GoodsStockHistoryService;

class GoodsStockHistoryRepository implements GoodsStockHistoryService{


    /**
     * 库存操作
     * @param $goods_id            商品id
     * @param $user_id             用户id
     * @param $describe            操作描述
     * @param $operation           库存操作，plus:加库存；reduce:减库存
     * @param $oper_type           操作类型， 0:单个操作；1: 后台批量操作;
     * @param $is_err              是否有误，0：无误，1：有误；
     * @return mixed
     */
    public function updateStockHistory($goods_id, $user_id, $describe, $number, $operation, $oper_type=0, $is_err=0){

        return GoodsStockHistory::insert(['goods_id' => $goods_id, 'user_id' => $user_id, 'describe' => $describe, 'stock_status' => $operation, 'number' => $number, 'add_time' => time(), 'oper_type' => $oper_type, 'is_err' => $is_err]);

    }//end func updateStock()


    /**
     * 根据商品id获取库存操作
     * @param $goods_sn            商品编号
     * @return mixed
     */
    public function getByGoodsId($goods_id){

        return GoodsStockHistory::where('goods_id', $goods_id)->get();

    }//end func getByGoodsId()

}//end class GoodsRepository